package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper//Mapper出于springboot，不加这个boot不知道你要创建代理对象，因为接口是不能创建对象的
public interface EmployeeMapper{
    @Select("select * from employee where username = #{username}")
    @Results({@Result(property = "idNumber", column = "id_number"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "updateUser", column = "update_user")})
    public Employee getByUsername(String username);

    @Select("select * from employee where name LIKE CONCAT('%', #{name}, '%')")
    @Results({@Result(property = "idNumber", column = "id_number"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "updateUser", column = "update_user")})
    public List<Employee> getByname(String name);

    @Insert("insert into employee values (#{id},#{name},#{username},#{password},#{phone},#{sex},#{idNumber},DEFAULT,#{createTime},#{updateTime},#{createUser},#{updateUser})")
    public int save(Employee employee);

    @Select("select * from employee ORDER BY create_time ASC")
    @Results({@Result(property = "idNumber", column = "id_number"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "updateUser", column = "update_user")})
    public List<Employee> getAll();

    @Update("update employee set name = #{name},username = #{username},password = #{password},phone = #{phone},sex = #{sex},id_number = #{idNumber},status = #{status} where id = #{id}")
    public int updateById(Employee employee);

    @Update("update employee set status = #{status} where id = #{id}")
    public int banById(Employee employee);

    @Select("select * from employee where id = #{id}")
    //表示实体类的idNumber对应数据库的id_number
    @Results({@Result(property = "idNumber", column = "id_number"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "updateUser", column = "update_user")})
    public Employee getById(Long id);
}
